/*
 * @Author: ujjldn ujjldn0515@163.com
 * @Date: 2025-06-01 18:03:48
 * @LastEditors: ujjldn ujjldn0515@163.com
 * @LastEditTime: 2025-06-26 20:55:09
 * @FilePath: \g-table\vite.config.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// vite.config.js
import vue from '@vitejs/plugin-vue'
import { defineConfig } from 'vite'
import {resolve} from 'path'

export default defineConfig({
  resolve: {
    alias: {
        "@": resolve(__dirname, 'src'), // 路径别名
    },
    extensions: ['.js', '.vue', '.json', '.ts'] // 使用路径别名时想要省略的后缀名，可以自己 增减
  },
  build: {
    outDir: './dist',
    lib: {
      entry: './gcardlist.js',
      name: 'GTable',
      fileName: (format) => `g-card-list.${format}.js`
    },
    rollupOptions: {
      external: ['vue', 'element-plus', 'axios'],
      output: {
        globals: {
          vue: 'Vue',
          'element-plus': 'ElementPlus',
          axios: 'axios'
        },
        assetFileNames: (assetInfo) => {
          if (assetInfo.name.endsWith('.css')) {
            return 'g-card-list.css';
          }
          return assetInfo.name;
        },
      }
    },
    // 添加 terser 选项以更好地处理编码问题
    minify: 'terser',
    terserOptions: {
      compress: {
        drop_console: true,
        drop_debugger: true
      },
      format: {
        ascii_only: true
      }
    }
  },
  plugins: [vue()],
  esbuild: {
    charset: 'utf8'
  },
  define: {
    __VUE_OPTIONS_API__: 'true',
    __VUE_PROD_DEVTOOLS__: 'false'
  }
})
